<ix-modal-header
  [requiredRoles]="requiredRoles"
  [title]="title"
  [loading]="isLoading"
></ix-modal-header>

<mat-card>
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <ix-fieldset>
        <ix-input
          formControlName="name"
          [label]="helptext.nameLabel | translate"
          [tooltip]="helptext.nameTooltip | translate"
          [required]="true"
        ></ix-input>
        <ix-input
          formControlName="comments"
          [label]="helptext.commentsLabel | translate"
        ></ix-input>
        <ix-input
          formControlName="volsize"
          [label]="helptext.sizeLabel | translate"
          [tooltip]="helptext.sizeTooltip | translate"
          [format]="formatter.memorySizeFormatting"
          [parse]="formatter.memorySizeParsing"
          [required]="true"
        ></ix-input>
        <ix-checkbox
          formControlName="force_size"
          [label]="helptext.forceSizeLabel | translate"
          [tooltip]="helptext.forceSizeTooltip | translate"
        ></ix-checkbox>
        <ix-select
          formControlName="sync"
          [label]="helptext.syncLabel | translate"
          [tooltip]="helptext.syncTooltip | translate"
          [options]="syncOptions$"
          [required]="true"
        ></ix-select>
        <ix-select
          formControlName="compression"
          [label]="helptext.compressionLabel | translate"
          [tooltip]="helptext.compressionTooltip | translate"
          [options]="compressionOptions$"
          [required]="true"
        ></ix-select>
        <ix-select
          formControlName="deduplication"
          [label]="helptext.deduplicationLabel | translate"
          [tooltip]="helptext.deduplicationTooltip | translate"
          [options]="deduplicationOptions$"
          [required]="true"
        ></ix-select>
        @if (form.controls.sparse.enabled) {
          <ix-checkbox
            formControlName="sparse"
            [label]="helptext.sparseLabel | translate"
            [tooltip]="helptext.sparseTooltip | translate"
          ></ix-checkbox>
        }
        <ix-select
          formControlName="readonly"
          [label]="helptext.readonlyLabel | translate"
          [tooltip]="helptext.readonlyTooltip | translate"
          [options]="readonlyOptions$"
          [required]="true"
        ></ix-select>
        @if (form.controls.volblocksize.enabled) {
          <ix-select
            formControlName="volblocksize"
            [label]="helptext.volblocksizeLabel | translate"
            [tooltip]="helptext.volblocksizeTooltip | translate"
            [options]="volblocksizeOptions$"
            [required]="true"
          ></ix-select>
        }
        <ix-select
          formControlName="snapdev"
          [label]="'Snapdev' | translate"
          [tooltip]="'Controls whether the volume snapshot devices under /dev/zvol/⟨pool⟩  are hidden or visible. The default value is hidden.' | translate"
          [options]="snapdevOptions$"
          [required]="true"
        ></ix-select>
      </ix-fieldset>
      @if (isNew) {
        <ix-fieldset [title]="helptext.encryption.title | translate">
          <ix-checkbox
            formControlName="inherit_encryption"
            [label]="inheritEncryptPlaceholder | translate"
            [tooltip]="helptext.encryption.inheritTooltip | translate"
          ></ix-checkbox>
          @if (!form.controls.inherit_encryption.value) {
            <ix-checkbox
              formControlName="encryption"
              [label]="helptext.encryption.encryptionLabel | translate"
              [tooltip]="helptext.encryption.encryptionTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.encryption_type.enabled) {
            <ix-select
              formControlName="encryption_type"
              [label]="helptext.encryption.encryptionTypeLabel | translate"
              [tooltip]="helptext.encryption.encryptionTypeTooltip | translate"
              [options]="encryptionTypeOptions$"
              [required]="true"
            ></ix-select>
          }
          @if (form.controls.generate_key.enabled) {
            <ix-checkbox
              formControlName="generate_key"
              [label]="helptext.encryption.generateKeyLabel | translate"
              [tooltip]="helptext.encryption.generateKeyTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.key.enabled) {
            <ix-textarea
              formControlName="key"
              [label]="helptext.encryption.keyLabel | translate"
              [tooltip]="helptext.encryption.keyTooltip | translate"
              [required]="true"
            ></ix-textarea>
          }
          @if (form.controls.passphrase.enabled) {
            <ix-input
              formControlName="passphrase"
              type="password"
              [label]="helptext.encryption.passphraseLabel | translate"
              [tooltip]="helptext.encryption.passphraseTooltip | translate"
              [required]="true"
            ></ix-input>
          }
          @if (form.controls.confirm_passphrase.enabled) {
            <ix-input
              formControlName="confirm_passphrase"
              type="password"
              [label]="helptext.encryption.confirmPassphraseLabel | translate"
              [required]="true"
            ></ix-input>
          }
          @if (form.controls.pbkdf2iters.enabled) {
            <ix-input
              formControlName="pbkdf2iters"
              [label]="helptext.encryption.pbkdf2itersLabel | translate"
              [tooltip]="helptext.encryption.pbkdf2itersTooltip | translate"
              [required]="true"
            ></ix-input>
          }
          @if (form.controls.algorithm.enabled) {
            <ix-select
              formControlName="algorithm"
              [label]="helptext.encryption.algorithmLabel | translate"
              [tooltip]="helptext.encryption.algorithmTooltip | translate"
              [options]="algorithmOptions$"
              [required]="true"
            ></ix-select>
          }
        </ix-fieldset>
      }

      <ix-form-actions>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isLoading"
        >{{ 'Save' | translate }}</button>
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
